package com.ai3d.rfid.common.dialog

import android.app.Activity
import android.view.View
import android.widget.TextView
import com.ai3d.rfid.R
import com.ai3d.rfid.base.dialog.BaseDialog
import com.ai3d.rfid.common.proxy.MMKVProxy
import com.bj.disc.ui.login.activity.LoginActivity

/**
 * @ProjectName : Trias
 * @Author : weijinsong
 * @Time : 2023/4/6 9:30
 * @Description : 文件描述
 */
class HintDialog(
    var hint: Int,
    var activity: Activity,
    var callBack: ((isConfirm: Boolean) -> Unit)? = null
) :
    BaseDialog(activity, R.style.AlertDialogThemeNoBackground) {
    companion object {
        var PAST_DUE_HINT = 1
        var CLEAR_RECENT_HINT = 2
    }

    private var tvTitle: TextView? = null
    private var tvTips: TextView? = null
    private var tvCancel: TextView? = null
    private var vLine: View? = null
    private var tvConfirm: TextView? = null

    override fun initView() {
        tvTitle = findViewById(R.id.tvTitle)
        tvTips = findViewById(R.id.tvTips)
        tvCancel = findViewById(R.id.tvCancel)
        vLine = findViewById(R.id.vLine)
        tvConfirm = findViewById(R.id.tvConfirm)

        when (hint) {
            PAST_DUE_HINT -> {
                tvTitle?.setText(R.string.hint)
                tvTips?.setText(R.string.account_past_due_tips)
            }
            CLEAR_RECENT_HINT -> {
                tvTips?.setText(R.string.clear_recent_use_tips)
                tvCancel?.visibility = View.VISIBLE
                vLine?.visibility = View.VISIBLE
            }
            else -> {
                tvTitle?.setText(R.string.hint)
                tvTips?.setText(R.string.account_past_due_tips)
            }
        }
    }

    override fun initEvent() {
        tvCancel?.setOnClickListener {
            dismiss()
        }
        tvConfirm?.setOnClickListener {
            dismiss()
            when (hint) {
                PAST_DUE_HINT -> {
                    MMKVProxy.logoutClear()
                    if(!(activity is LoginActivity)) {
                        LoginActivity.startLoginActivity(activity)
                        activity?.finish()
                    }
                }
                CLEAR_RECENT_HINT -> {

                }
                else -> {

                }
            }

            callBack?.invoke(true)
        }
    }

    override fun initData() {

    }

    override fun getLayoutId(): Int {
        return R.layout.dialog_hint
    }

    override fun getAnimId(): Int {
        return -1
    }
}